package com.godz.frontData.index2;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.index2TeacherMapper;
import com.godz.pojo.index2Teacher;
import org.springframework.web.bind.annotation.*;
import java.util.List;

//我的恩师
@RestController
public class teacherData {
    final
    index2TeacherMapper teacherMapper;

    public teacherData(index2TeacherMapper teacherMapper) {
        this.teacherMapper = teacherMapper;
    }

    @GetMapping("/index2/get/index2Teacher")
    public List<index2Teacher> getTeacher(){
        return teacherMapper.selectList(null);
    }
    //查询单个
    @GetMapping("/index2/get/index2Teacher/{intId}")
    public index2Teacher getOneTeacher(@PathVariable("intId") Integer integer) {
        return teacherMapper.selectOne(
                new QueryWrapper<index2Teacher>().eq("id", integer)
        );
    }
    //增加一条
    @PostMapping("/index2/post/addTeacher")
    public String addTeacher(@RequestBody index2Teacher teacher) {
        teacherMapper.insert(teacher);
        return "insert OK";
    }
    //修改一条
    @PostMapping("/index2/post/editTeacher")
    public String editTeacher(@RequestBody index2Teacher teacher) {
        QueryWrapper<index2Teacher> wrapper = new QueryWrapper<>();
        wrapper.eq("id", teacher.getId());

        index2Teacher teacher1 = new index2Teacher();
        teacher1.setTeName(teacher.getTeName());
        teacher1.setTeStatus(teacher.getTeStatus());
        teacher1.setTeImg(teacher.getTeImg());
        teacher1.setTeIntroduce(teacher.getTeIntroduce());

        teacherMapper.update(teacher1, wrapper);
        return "Update OK";
    }
    //删除一条
    @GetMapping("/index2/get/deleteTeacher/{id}")
    public String deleteTeacher(@PathVariable("id") Integer integer) {
        teacherMapper.deleteById(integer);
        return "Delete Ok";
    }

}
